public GetProperty ( string name ) : PropertyInfo | ||
name | string | The string containing the name of the public property to get. |
return | PropertyInfo |
/// <summary> /// Создает на основе типа фильтр /// </summary> /// <param name="lib"></param> /// <param name="type"></param> public Filter(string lib, Type type) { libname = lib; if (type.BaseType == typeof(AbstractFilter)) { Exception fullex = new Exception(""); ConstructorInfo ci = type.GetConstructor(System.Type.EmptyTypes); filter = ci.Invoke(null); PropertyInfo everyprop; everyprop = type.GetProperty("Name"); name = (string)everyprop.GetValue(filter, null); everyprop = type.GetProperty("Author"); author = (string)everyprop.GetValue(filter, null); everyprop = type.GetProperty("Ver"); version = (Version)everyprop.GetValue(filter, null); help = type.GetMethod("Help"); MethodInfo[] methods = type.GetMethods(); filtrations = new List<Filtration>(); foreach (MethodInfo mi in methods) if (mi.Name == "Filter") { try { filtrations.Add(new Filtration(mi)); } catch (TypeLoadException) { //Не добавляем фильтрацию. } } if (filtrations == null) throw new TypeIncorrectException("Класс " + name + " не содержит ни одной фильтрации"); } else throw new TypeLoadException("Класс " + type.Name + " не наследует AbstractFilter"); }
public NullableMembers(Type elementType) { NullableType = NullableTypeDefinition.MakeGenericType(elementType); Constructor = NullableType.GetConstructor(new[] { elementType }); GetHasValue = NullableType.GetProperty("HasValue").GetGetMethod(); GetValue = NullableType.GetProperty("Value").GetGetMethod(); }
static ProjectElement() { s_projectElement = Type.GetType( "Microsoft.Build.Construction.ProjectElement, Microsoft.Build, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", false, false); if (s_projectElement != null) { s_projectElementLocation = s_projectElement.GetProperty("Location"); } s_elementLocation = Type.GetType( "Microsoft.Build.Construction.ElementLocation, Microsoft.Build, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", false, false); if (s_elementLocation != null) { s_elementLocationFile = s_elementLocation.GetProperty("File"); s_elementLocationLine= s_elementLocation.GetProperty("Line"); s_elementLocationColumn = s_elementLocation.GetProperty("Column"); s_elementLocationLocationString = s_elementLocation.GetProperty("LocationString"); } }
public DisplayStringAttribute(Type resourceManagerType, string resourceKey) { PropertyInfo property = resourceManagerType.GetProperty(resourceKey); if (property == (PropertyInfo) null) property = resourceManagerType.GetProperty(resourceKey, BindingFlags.Static | BindingFlags.NonPublic); this.Value = property.GetValue((object) null, (object[]) null) as string; }
/// <summary> /// CCtor /// </summary> static DataContractResolverStrategy() { string[] assemblyName = typeof(Object).Assembly.FullName.Split(','); assemblyName[0] = DataContractAssemblyName; Assembly assembly = Assembly.Load(String.Join(",", assemblyName)); DataContractType = assembly.GetType(DataContractTypeName); DataMemberType = assembly.GetType(DataMemberTypeName); IgnoreDataMemberType = assembly.GetType(IgnoreDataMemberTypeName); if (DataContractType != null) { PropertyInfo property = DataContractType.GetProperty("Name", BindingFlags.Public|BindingFlags.Instance|BindingFlags.FlattenHierarchy); DataContractNameGetter = DynamicMethodGenerator.GetPropertyGetter(property); property = DataContractType.GetProperty("Namespace", BindingFlags.Public|BindingFlags.Instance|BindingFlags.FlattenHierarchy); DataContractNamespaceGetter = DynamicMethodGenerator.GetPropertyGetter(property); } if (DataContractResolverStrategy.DataMemberType != null) { PropertyInfo property = DataMemberType.GetProperty("Name", BindingFlags.Public|BindingFlags.Instance|BindingFlags.FlattenHierarchy); DataMemberNameGetter = DynamicMethodGenerator.GetPropertyGetter(property); } }
object Read(XmlReader reader, Type type) { var obj = Activator.CreateInstance(type); if (reader.HasAttributes) { reader.MoveToFirstAttribute(); do { var propertyInfo = type.GetProperty(reader.Name); propertyInfo .SetValue( obj, Convert.ChangeType(reader.Value, propertyInfo.PropertyType) ); } while (reader.MoveToNextAttribute()); } while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: var propertyInfo = type.GetProperty(reader.Name); propertyInfo .SetValue( obj, ReadValue(reader, propertyInfo.PropertyType) ); break; } } return obj; }
public static IEnumerable<ObjectVariableBase> GetAudioEchoFilterVariables(Type type) { yield return new ObjectPropertyVariable(type.GetProperty("delay")); yield return new ObjectPropertyVariable(type.GetProperty("decayRatio")); yield return new ObjectPropertyVariable(type.GetProperty("dryMix")); yield return new ObjectPropertyVariable(type.GetProperty("wetMix")); }
public void Setup() { m_studType = typeof(Student); m_idProperty = m_studType.GetProperty("ID"); m_nameProperty = m_studType.GetProperty("Name"); m_scoreProperty = m_studType.GetProperty("Score"); }
public void FromController(Type ctrl) { ProductCode = (string)ctrl.GetProperty("ProductCode", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public).GetValue(null, null); ProductName = (string)ctrl.GetProperty("ProductName", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public).GetValue(null, null); ProductKey = (string)ctrl.GetProperty("ProductKey", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public).GetValue(null, null); Version = (string)ctrl.GetProperty("Version", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public).GetValue(null, null); }
static API() { var editorAssembly = typeof(EditorWindow).Assembly; containerWindowType = editorAssembly.GetType("UnityEditor.ContainerWindow"); viewType = editorAssembly.GetType("UnityEditor.View"); dockAreaType = editorAssembly.GetType("UnityEditor.DockArea"); parentField = typeof(EditorWindow).GetField("m_Parent", BindingFlags.Instance | BindingFlags.GetField | BindingFlags.Public | BindingFlags.NonPublic); if (dockAreaType != null) { panesField = dockAreaType.GetField("m_Panes", BindingFlags.Instance | BindingFlags.GetField | BindingFlags.Public | BindingFlags.NonPublic); addTabMethod = dockAreaType.GetMethod("AddTab", new System.Type[] { typeof(EditorWindow) }); } if (containerWindowType != null) { windowsField = containerWindowType.GetProperty("windows", BindingFlags.Static | BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.NonPublic); mainViewField = containerWindowType.GetProperty("mainView", BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.NonPublic); } if (viewType != null) allChildrenField = viewType.GetProperty("allChildren", BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.NonPublic); FieldInfo windowsReorderedField = typeof(EditorApplication).GetField("windowsReordered", BindingFlags.Static | BindingFlags.GetField | BindingFlags.Public | BindingFlags.NonPublic); windowsReordered = windowsReorderedField.GetValue(null) as EditorApplication.CallbackFunction; System.Type projectWindowUtilType = editorAssembly.GetType("UnityEditor.ProjectWindowUtil"); if (projectWindowUtilType != null) createAssetMethod = projectWindowUtilType.GetMethod("CreateAsset", new System.Type[] { typeof(Object), typeof(string) }); }
static ZipTools() { try { var windowsBase = typeof (Package).Assembly; ZipArchive = windowsBase.GetType("MS.Internal.IO.Zip.ZipArchive"); ZipArchive_OpenOnFile = ZipArchive.GetMethod("OpenOnFile", BindingFlags.NonPublic | BindingFlags.Static); ZipArchive_GetFiles = ZipArchive.GetMethod("GetFiles", BindingFlags.NonPublic | BindingFlags.Instance); ZipArchive_ZipIOBlockManager = ZipArchive.GetField("_blockManager", BindingFlags.NonPublic | BindingFlags.Instance); ZipFileInfo = windowsBase.GetType("MS.Internal.IO.Zip.ZipFileInfo"); ZipFileInfo_GetStream = ZipFileInfo.GetMethod("GetStream", BindingFlags.NonPublic | BindingFlags.Instance); ZipFileInfo_Name = ZipFileInfo.GetProperty("Name", BindingFlags.NonPublic | BindingFlags.Instance); ZipFileInfo_FolderFlag = ZipFileInfo.GetProperty("FolderFlag", BindingFlags.NonPublic | BindingFlags.Instance); ZipIOBlockManager = windowsBase.GetType("MS.Internal.IO.Zip.ZipIOBlockManager"); ZipIOBlockManager_Encoding = ZipIOBlockManager.GetField("_encoding", BindingFlags.NonPublic | BindingFlags.Instance); Enabled = true; } catch { Enabled = false; } }
/// <summary>Select interceptors which must be applied to the method.</summary> /// <param name="type">The type.</param> /// <param name="method">The method.</param> /// <param name="interceptors">The interceptors.</param> /// <returns>The interceptors after filtering.</returns> public IInterceptor[] SelectInterceptors(Type type, MethodInfo method, IInterceptor[] interceptors) { if (method.IsGetter()) { var propertyInfo = type.GetProperty(method); if (propertyInfo.IsPropertyWithSelectorAttribute()) { return typeof(BaseHtmlElement).IsAssignableFrom(method.ReturnType) ? interceptors.Where(x => x is PropertyInterceptor).ToArray() : interceptors.Where(x => x is CollectionPropertyInterceptor).ToArray(); } } if (method.IsSetter()) { var propertyInfo = type.GetProperty(method); if (propertyInfo.IsPropertyWithSelectorAttribute()) { return interceptors.Where(x => x is InvalidWriteOperationInterceptor).ToArray(); } } return interceptors.Where(x => !(x is PropertyInterceptor) && !(x is CollectionPropertyInterceptor) && !(x is InvalidWriteOperationInterceptor)).ToArray(); }
public void GenerateWriterMethod(Type type, CodeGenContext ctx, ILGenerator il) { var valueType = type.GetGenericArguments()[0]; var noValueLabel = il.DefineLabel(); MethodInfo getHasValue = type.GetProperty("HasValue").GetGetMethod(); MethodInfo getValue = type.GetProperty("Value").GetGetMethod(); var data = ctx.GetTypeDataForCall(valueType); il.Emit(OpCodes.Ldarg_1); // Stream il.Emit(OpCodes.Ldarga_S, 2); // &value il.Emit(OpCodes.Call, getHasValue); il.Emit(OpCodes.Call, ctx.GetWriterMethodInfo(typeof(bool))); il.Emit(OpCodes.Ldarga_S, 2); // &value il.Emit(OpCodes.Call, getHasValue); il.Emit(OpCodes.Brfalse_S, noValueLabel); if (data.NeedsInstanceParameter) il.Emit(OpCodes.Ldarg_0); // Serializer il.Emit(OpCodes.Ldarg_1); // Stream il.Emit(OpCodes.Ldarga_S, 2); // &value il.Emit(OpCodes.Call, getValue); // XXX for some reason Tailcall causes huge slowdown, at least with "decimal?" //il.Emit(OpCodes.Tailcall); il.Emit(OpCodes.Call, data.WriterMethodInfo); il.MarkLabel(noValueLabel); il.Emit(OpCodes.Ret); }
/// <summary> /// Initializes a new instance of the <see cref="EmitPropertyGetAccessor"/> class. /// </summary> /// <param name="targetObjectType">Type of the target object.</param> /// <param name="propertyName">Name of the property.</param> /// <param name="assemblyBuilder">The <see cref="AssemblyBuilder"/>.</param> /// <param name="moduleBuilder">The <see cref="ModuleBuilder"/>.</param> public EmitPropertyGetAccessor(Type targetObjectType, string propertyName, AssemblyBuilder assemblyBuilder, ModuleBuilder moduleBuilder) { _targetType = targetObjectType; _propertyName = propertyName; // deals with Overriding a property using new and reflection // http://blogs.msdn.com/thottams/archive/2006/03/17/553376.aspx PropertyInfo propertyInfo = _targetType.GetProperty(propertyName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); if (propertyInfo == null) { propertyInfo = _targetType.GetProperty(propertyName); } // Make sure the property exists if(propertyInfo == null) { throw new NotSupportedException( string.Format("Property \"{0}\" does not exist for type " + "{1}.", propertyName, _targetType)); } else { this._propertyType = propertyInfo.PropertyType; _canRead = propertyInfo.CanRead; this.EmitIL(assemblyBuilder, moduleBuilder); } }
static ProjectHelper() { const BindingFlags bindingFlags = BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy; SolutionParserType = TypeCache.GetType("Microsoft.Build.Construction.SolutionParser"); if (SolutionParserType != null) { SolutionReaderPropertyInfo = SolutionParserType.GetProperty("SolutionReader", bindingFlags); ProjectsPropertyInfo = SolutionParserType.GetProperty("Projects", bindingFlags); ParseSolutionMethodInfo = SolutionParserType.GetMethod("ParseSolution", bindingFlags); } var projectInSolutionType = TypeCache.GetType("Microsoft.Build.Construction.ProjectInSolution"); if (projectInSolutionType != null) { RelativePathPropertyInfo = projectInSolutionType.GetProperty("RelativePath", bindingFlags); ProjectTypePropertyInfo = projectInSolutionType.GetProperty("ProjectType", bindingFlags); } var solutionProjectTypeType = TypeCache.GetType("Microsoft.Build.Construction.SolutionProjectType"); if (solutionProjectTypeType != null) { KnownToBeMsBuildFormat = Enum.Parse(solutionProjectTypeType, "KnownToBeMSBuildFormat"); } }
public virtual void GenerateWriterMethod(Serializer serializer, Type type, ILGenerator il) { var valueType = type.GetGenericArguments()[0]; var noValueLabel = il.DefineLabel(); MethodInfo getHasValue = type.GetProperty("HasValue").GetGetMethod(); MethodInfo getValue = type.GetProperty("Value").GetGetMethod(); var data = serializer.GetIndirectData(valueType); il.Emit(OpCodes.Ldarg_1); // Stream il.Emit(OpCodes.Ldarga_S, 2); // &value il.Emit(OpCodes.Call, getHasValue); il.Emit(OpCodes.Call, serializer.GetDirectWriter(typeof(bool))); il.Emit(OpCodes.Ldarga_S, 2); // &value il.Emit(OpCodes.Call, getHasValue); il.Emit(OpCodes.Brfalse_S, noValueLabel); if (data.WriterNeedsInstance) il.Emit(OpCodes.Ldarg_0); // Serializer il.Emit(OpCodes.Ldarg_1); // Stream il.Emit(OpCodes.Ldarga_S, 2); // &value il.Emit(OpCodes.Call, getValue); // XXX for some reason Tailcall causes huge slowdown, at least with "decimal?" //il.Emit(OpCodes.Tailcall); il.Emit(OpCodes.Call, data.WriterMethodInfo); il.MarkLabel(noValueLabel); il.Emit(OpCodes.Ret); }
public Logging() { _loggingType = Type.GetType("System.Net.Logging, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); if (_loggingType == null) { return; } var webProperty = _loggingType.GetProperty("Web", BindingFlags.NonPublic | BindingFlags.Static); if (webProperty != null) { Sources.Add((TraceSource)webProperty.GetValue(null)); } var socketsProperty = _loggingType.GetProperty("Sockets", BindingFlags.NonPublic | BindingFlags.Static); if (socketsProperty != null) { Sources.Add((TraceSource)socketsProperty.GetValue(null)); } var webSocketsProperty = _loggingType.GetProperty("WebSockets", BindingFlags.NonPublic | BindingFlags.Static); if (webSocketsProperty != null) { Sources.Add((TraceSource)webSocketsProperty.GetValue(null)); } }
public object ConvertToObject(IDictionary<string, object> dictionary, Type type) { var obj = Activator.CreateInstance(type); foreach (var entry in dictionary) { var fieldType = type.GetProperty(entry.Key).PropertyType; var valueType = entry.Value.GetType(); if (typeof(IDictionary).IsAssignableFrom(valueType)) { ConvertToObject((IDictionary<string, object>)entry.Value, fieldType); } else { if (typeof(IList).IsAssignableFrom(fieldType)) { Type argType = fieldType.GetGenericArguments()[0]; var listObj = Activator.CreateInstance(fieldType); foreach (var val in (IList)entry.Value) { ((IList)listObj).Add(ConvertToObject((IDictionary<string, object>)val, argType)); } } else { type.GetProperty(entry.Key).SetValue(obj, entry.Value, null); } } } return obj; }
private void CheckHasMethodRemoved(Type proto2Type, Type proto3Type, string name) { Assert.NotNull(proto2Type.GetProperty(name)); Assert.NotNull(proto2Type.GetProperty("Has" + name)); Assert.NotNull(proto3Type.GetProperty(name)); Assert.Null(proto3Type.GetProperty("Has" + name)); }
public static bool IsInteresting(Type t) { if (t == null || t.Namespace == null) return false; if (t.IsEnum || !t.Namespace.StartsWith(SchemaBuilder.Linq2AzureNamespace)) return false; if (t.GetProperty("Subscription") == null && t.GetProperty("Parent") == null) return false; return true; }
public static IEnumerable<ObjectVariableBase> GetAnimationClipVariables(Type type) { yield return new ObjectPropertyVariable(type.GetProperty("wrapMode")); yield return new ObjectPropertyVariable(type.GetProperty("localBounds")); yield return new UnityPropertyVariable("m_Compressed", SerializedPropertyType.Boolean); yield return new UnityPropertyVariable("m_SampleRate", SerializedPropertyType.Float); }
/// <summary> /// Initialize entity metadata. /// </summary> /// <param name="entityType"></param> protected EntityMetadataBase(Type entityType) { if (entityType == null) throw new ArgumentNullException("entityType"); Type = entityType; var key = entityType.GetProperties().FirstOrDefault(t => t.GetCustomAttribute<KeyAttribute>() != null); if (key != null) KeyType = key.PropertyType; else { key = entityType.GetProperty("Index"); if (key != null) KeyType = key.PropertyType; else { key = entityType.GetProperty("Id"); if (key != null) KeyType = key.PropertyType; else { key = entityType.GetProperty("ID"); if (key != null) KeyType = key.PropertyType; } } } }
public FasterImplementationTests() { _mc = new MyClass(); _tp = typeof (MyClass); _propId = _tp.GetProperty("Id"); _propName = _tp.GetProperty("Name"); _propCreated = _tp.GetProperty("CreatedOn"); }
public static IEnumerable<ObjectVariableBase> GetAnimationVariables(Type type) { yield return new ObjectPropertyVariable(type.GetProperty("clip")); yield return new ObjectPropertyVariable(type.GetProperty("playAutomatically")); yield return new ObjectPropertyVariable(type.GetProperty("animatePhysics")); yield return new ObjectPropertyVariable(type.GetProperty("cullingType")); yield return new AnimationsVariable(); }
private void GenerateDictionaryCode(ILCodeVariable dictionary, Type elementType) { var enumerateCode = new ILEnumerateCode(dictionary, (il, it) => { GenerateEnumerateContentCode(new InstancePropertyILCodeVariable(it, elementType.GetProperty("Key")), LevelType.DictionaryKey); GenerateEnumerateContentCode(new InstancePropertyILCodeVariable(it, elementType.GetProperty("Value")), LevelType.DictionaryValue); }); _il.Generate(enumerateCode); }
public void LoadFrom(string basePath) { _LicenseDllAssembly = Assembly.LoadFrom(basePath + DllName); _DemoType = _LicenseDllAssembly.GetType(_TypeName); _StartOf = _DemoType.GetProperty("StartOf"); _ValidFor = _DemoType.GetProperty("ValidFor"); _Ticks = _DemoType.GetProperty("Ticks"); }
//public static SqlParameterCollection Sqlparams; public static void AddItem(IList list, Type type, string valueMember,string displayMember, string displayText) { Object obj = Activator.CreateInstance(type); PropertyInfo displayProperty = type.GetProperty(displayMember); displayProperty.SetValue(obj, displayText, null); PropertyInfo valueProperty = type.GetProperty(valueMember); valueProperty.SetValue(obj, -1, null); list.Insert(0, obj); }
public static void AddItemsStaff(IList<tStaff> list, Type type, string valueMember, string displayMember, string displayText) { var obj = Activator.CreateInstance(type); var displayProperty = type.GetProperty(displayMember); displayProperty.SetValue(obj, displayText, null); var valueProperty = type.GetProperty(valueMember); valueProperty.SetValue(obj, -1, null); list.Insert(0, obj as tStaff); }
public string FindIdMember(Type type) { if (type.GetProperty("Id") != null) return "Id"; if (type.GetProperty("Key") != null) return "Key"; return null; }
static Solution() { s_SolutionParser = Type.GetType("Microsoft.Build.Construction.SolutionParser, Microsoft.Build, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", false, false); if (s_SolutionParser != null) { s_SolutionParser_solutionReader = s_SolutionParser.GetProperty("SolutionReader", BindingFlags.NonPublic | BindingFlags.Instance); s_SolutionParser_projects = s_SolutionParser.GetProperty("Projects", BindingFlags.NonPublic | BindingFlags.Instance); s_SolutionParser_parseSolution = s_SolutionParser.GetMethod("ParseSolution", BindingFlags.NonPublic | BindingFlags.Instance); } }
private IEnumerator Start() { KX = 1.0f; KY = 1.0f; RegionCaptureMaterial = GetComponent <Renderer>().material; if (!UseCustomBackgroundMaterial) { CustomBackgroundMaterial = null; } else if (CustomBackgroundMaterial == null) { System.Type checkArFoundation = System.Type.GetType("UnityEngine.XR.ARFoundation.ARCameraBackground, Unity.XR.ARFoundation"); if (checkArFoundation != null) { var checkObjectInScene = FindObjectOfType(checkArFoundation); if (checkObjectInScene) { UseARFoundation = true; if (!Application.isEditor) { CustomBackgroundMaterial = checkArFoundation.GetProperty("material").GetValue(checkObjectInScene) as Material; } } } } yield return(StartCoroutine(Initialize())); StartCoroutine(Check_StateLoop()); }
Vector3 getRotation(Transform transform1) { System.Type transformType = transform1.GetType(); PropertyInfo m_propertyInfo_rotationOrder = transformType.GetProperty("rotationOrder", BindingFlags.Instance | BindingFlags.NonPublic); object m_OldRotationOrder = m_propertyInfo_rotationOrder.GetValue(transform1, null); MethodInfo m_methodInfo_GetLocalEulerAngles = transformType.GetMethod("GetLocalEulerAngles", BindingFlags.Instance | BindingFlags.NonPublic); object value = m_methodInfo_GetLocalEulerAngles.Invoke(transform1, new object[] { m_OldRotationOrder }); //Debug.Log("反射调用GetLocalEulerAngles方法获得的值:" + value.ToString()); string temp = value.ToString(); //将字符串第一个和最后一个去掉 temp = temp.Remove(0, 1); temp = temp.Remove(temp.Length - 1, 1); //用‘,’号分割 string[] tempVector3; tempVector3 = temp.Split(','); //将分割好的数据传给Vector3 Vector3 vector3 = new Vector3(float.Parse(tempVector3[0]), float.Parse(tempVector3[1]), float.Parse(tempVector3[2])); return(vector3); }
void Start() { missile = Trans.FindObj(gameObject, "spacecraft04_paodan"); position = missile.transform.position; EulerAngles = missile.transform.eulerAngles; LocalPosition = missile.transform.localPosition; LocalEulerAngles = missile.transform.localEulerAngles; Debug.Log("missile." + "position:" + missile.transform.position + "eulerAngles:" + missile.transform.eulerAngles // + ",rotation.eulerAngles:" + missile.transform.rotation.eulerAngles + ",rotation:" + missile.transform.rotation + "localPosition:" + missile.transform.localPosition + "localEulerAngles:" + missile.transform.localEulerAngles + "localRotation:" + missile.transform.localRotation ); // 获取原生值 System.Type transformType = missile.transform.GetType(); PropertyInfo m_propertyInfo_rotationOrder = transformType.GetProperty("rotationOrder", BindingFlags.Instance | BindingFlags.NonPublic); object m_OldRotationOrder = m_propertyInfo_rotationOrder.GetValue(missile.transform, null); MethodInfo m_methodInfo_GetLocalEulerAngles = transformType.GetMethod("GetLocalEulerAngles", BindingFlags.Instance | BindingFlags.NonPublic); object value = m_methodInfo_GetLocalEulerAngles.Invoke(missile.transform, new object[] { m_OldRotationOrder }); Debug.LogError("反射调用GetLocalEulerAngles方法获得的值:" + value.ToString()); Debug.LogError("transform.localEulerAngles获取的值:" + missile.transform.localEulerAngles.ToString()); }
// Use this for initialization void Start() { gestureRecog = gameObject.GetComponent <BaiduARGestureRecog> (); particle = particleObj.transform.GetComponent <ParticleSystem> (); if (isStartHandTracking) { System.Type type = particle.main.GetType(); PropertyInfo property = type.GetProperty("loop"); property.SetValue(particle.main, true, null); } //手势识别 gestureRecog.OnResultCallBack((bool result) => { if (!isStartHandTracking) { ShowObject(result); } }); //实验室功能 手势跟踪 gestureRecog.OnResultTrackCallBack((List <RecogGesture> lstRecg) => { //ARDebug.Log("lstRecg.Count; "+lstRecg.Count); //recogList = lstRecg; if (isStartHandTracking) { MoveObject(lstRecg); } }); }
private static string[] GetSortingLayerNames() { if (sortingLayerNamesPropInfo == null && !sortingLayerNamesChecked) { sortingLayerNamesChecked = true; try { System.Type IEU = System.Type.GetType("UnityEditorInternal.InternalEditorUtility,UnityEditor"); if (IEU != null) { sortingLayerNamesPropInfo = IEU.GetProperty("sortingLayerNames", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public); } } catch { } if (sortingLayerNamesPropInfo == null) { Debug.Log("tk2dEditorUtility - Unable to get sorting layer names."); } } if (sortingLayerNamesPropInfo != null) { return(sortingLayerNamesPropInfo.GetValue(null, null) as string[]); } else { return(new string[0]); } }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // * New Method: Draw Sprite Renderer Options //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ private void DrawSpriteRendererOptions(SpriteRenderer SRend, string sLabel = "Sprite Renderer") { EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.LabelField(sLabel, EditorStyles.boldLabel); SRend.sprite = EditorGUILayout.ObjectField("Sprite: ", SRend.sprite, typeof(Sprite), true) as Sprite; SRend.color = EditorGUILayout.ColorField("Colour: ", SRend.color); SRend.sharedMaterial = EditorGUILayout.ObjectField("Material: ", SRend.sharedMaterial, typeof(Material), true) as Material; // Sorting Layer System.Type internalEditorUtilityType = typeof(InternalEditorUtility); PropertyInfo sortingLayersProperty = internalEditorUtilityType.GetProperty("sortingLayerNames", BindingFlags.Static | BindingFlags.NonPublic); string[] aSortingLayerNames = (string[])sortingLayersProperty.GetValue(null, new object[0]); int iSortingLayerSelectedOption = 0; for (int i = 0; i < aSortingLayerNames.Length; ++i) { if (aSortingLayerNames[i] == SRend.sortingLayerName) { iSortingLayerSelectedOption = i; break; } } iSortingLayerSelectedOption = EditorGUILayout.Popup("Sorting Layer: ", iSortingLayerSelectedOption, aSortingLayerNames); SRend.sortingLayerName = aSortingLayerNames[iSortingLayerSelectedOption]; // Sorting Order SRend.sortingOrder = EditorGUILayout.IntField("Order in Layer: ", SRend.sortingOrder); }
/// <summary> /// 复制属性到另一个对象中(可以不同类型)。 /// </summary> /// <param name="model">当前对象。</param> /// <param name="toModel">目标对象。</param> /// <param name="predicate">过滤器。</param> public static void CopyTo( #if !net20 this #endif object model, object toModel, System.Predicate <System.Reflection.PropertyInfo> predicate) { Symbol.CommonException.CheckArgumentNull(model, "model"); Symbol.CommonException.CheckArgumentNull(toModel, "toModel"); System.Type type = model.GetType(); System.Type toType = toModel.GetType(); foreach (System.Reflection.PropertyInfo propertyInfo in type.GetProperties(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance)) { if (!propertyInfo.CanRead || propertyInfo.GetIndexParameters().Length > 0) { continue; } System.Reflection.PropertyInfo toPropertyInfo = toType.GetProperty(propertyInfo.Name, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance); if (toPropertyInfo == null || !toPropertyInfo.CanWrite) { continue; } if (predicate != null && !predicate(propertyInfo)) { continue; } toPropertyInfo.SetValue(toModel, TypeExtensions.Convert(propertyInfo.GetValue(model, null), toPropertyInfo.PropertyType), null); } }
private List <string> getSortingLayerNames() { System.Type internalEditorUtilityType = typeof(InternalEditorUtility); PropertyInfo sortingLayersProperty = internalEditorUtilityType.GetProperty("sortingLayerNames", BindingFlags.Static | BindingFlags.NonPublic); return(((string[])sortingLayersProperty.GetValue(null, new object[0])).ToList()); }
static API() { var editorAssembly = typeof(EditorWindow).Assembly; containerWindowType = editorAssembly.GetType("UnityEditor.ContainerWindow"); viewType = editorAssembly.GetType("UnityEditor.View"); dockAreaType = editorAssembly.GetType("UnityEditor.DockArea"); parentField = typeof(EditorWindow).GetField("m_Parent", BindingFlags.Instance | BindingFlags.GetField | BindingFlags.Public | BindingFlags.NonPublic); if (dockAreaType != null) { panesField = dockAreaType.GetField("m_Panes", BindingFlags.Instance | BindingFlags.GetField | BindingFlags.Public | BindingFlags.NonPublic); addTabMethod = dockAreaType.GetMethod("AddTab", new System.Type[] { typeof(EditorWindow) }); } if (containerWindowType != null) { windowsField = containerWindowType.GetProperty("windows", BindingFlags.Static | BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.NonPublic); mainViewField = containerWindowType.GetProperty("mainView", BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.NonPublic); } if (viewType != null) allChildrenField = viewType.GetProperty("allChildren", BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.NonPublic); FieldInfo windowsReorderedField = typeof(EditorApplication).GetField("windowsReordered", BindingFlags.Static | BindingFlags.GetField | BindingFlags.Public | BindingFlags.NonPublic); windowsReordered = windowsReorderedField.GetValue(null) as EditorApplication.CallbackFunction; System.Type projectWindowUtilType = editorAssembly.GetType("UnityEditor.ProjectWindowUtil"); if (projectWindowUtilType != null) createAssetMethod = projectWindowUtilType.GetMethod("CreateAsset", new System.Type[] { typeof(Object), typeof(string) }); }
private static object GetValue(object source, string name) { if (source == null) { return(null); } System.Type type = source.GetType(); while (type != null) { FieldInfo fieldInfo = type.GetField(name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); if (fieldInfo != null) { return(fieldInfo.GetValue(source)); } PropertyInfo propertyInfo = type.GetProperty(name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase); if (propertyInfo != null) { return(propertyInfo.GetValue(source, null)); } type = type.BaseType; } return(null); }
public int[] GetSortingLayerUniqueIDs() { System.Type internalEditorUtilityType = typeof(InternalEditorUtility); PropertyInfo sortingLayerUniqueIDsProperty = internalEditorUtilityType.GetProperty("sortingLayerUniqueIDs", BindingFlags.Static | BindingFlags.NonPublic); return((int[])sortingLayerUniqueIDsProperty.GetValue(null, new object[0])); }
/// <summary> /// get the sorting layer names<para/> /// from : http://answers.unity3d.com/questions/585108/how-do-you-access-sorting-layers-via-scripting.html /// </summary> /// <returns>The Sorting Layers (as string[])</returns> static public string[] getSortingLayerNames() { System.Type internalEditorUtilityType = typeof(UnityEditorInternal.InternalEditorUtility); PropertyInfo sortingLayersProperty = internalEditorUtilityType.GetProperty("sortingLayerNames", BindingFlags.Static | BindingFlags.NonPublic); return((string[])sortingLayersProperty.GetValue(null, new object[0])); }// getSortingLayerNames()
/// <summary> /// 获取属性的Description /// </summary> /// <param name="type"></param> /// <param name="propertyName"></param> /// <returns></returns> public static string GetPropertyDescription(this Type type, string propertyName) { DescriptionAttribute desc = (DescriptionAttribute)type?.GetProperty(propertyName)? .GetCustomAttributes(typeof(DescriptionAttribute), false) .FirstOrDefault(); return(desc?.Description); }
/// <summary> /// Perform one-off setup when class is accessed for first time. /// </summary> static GradientWrapper() { #if (UNITY_3_5 || UNITY_3_6 || UNITY_3_7 || UNITY_3_8 || UNITY_3_9) Assembly editorAssembly = typeof(Editor).Assembly; s_tyGradientColorKey = editorAssembly.GetType("UnityEditor.GradientColorKey"); s_tyGradientAlphaKey = editorAssembly.GetType("UnityEditor.GradientAlphaKey"); // Note that `Gradient` is defined in the editor namespace in Unity 3.5.7! s_tyGradient = editorAssembly.GetType("UnityEditor.Gradient"); s_miEvaluate = s_tyGradient.GetMethod("CalcColor", BindingFlags.Public | BindingFlags.Instance, null, new Type[] { typeof(float) }, null); s_piColorKeys = s_tyGradient.GetProperty("colorKeys", BindingFlags.Public | BindingFlags.Instance); s_piAlphaKeys = s_tyGradient.GetProperty("alphaKeys", BindingFlags.Public | BindingFlags.Instance); #else // In Unity 4 this is easy :) s_tyGradient = typeof(Gradient); #endif }
public static void SimpleParseASN1(string publicKey, ref byte[] modulus, ref byte[] exponent) { byte[] publicKey64 = System.Convert.FromBase64String(publicKey); // The ASN1 structure for the public key looks like this: // // SubjectPublicKeyInfo ::= SEQUENCE { // algorithm AlgorithmIdentifier, // publicKey BIT STRING } // // Where the BIT STRING is a SEQUENCE of 2 INTEGERs (the modulus and the exponent) System.Type ASN1 = System.Type.GetType("Mono.Security.ASN1"); System.Reflection.ConstructorInfo Ctor = ASN1.GetConstructor(new System.Type[] { typeof(byte[]) }); System.Reflection.PropertyInfo Value = ASN1.GetProperty("Value"); System.Reflection.PropertyInfo Item = ASN1.GetProperty("Item"); object asn = Ctor.Invoke(new object[] { publicKey64 }); object bits = Item.GetValue(asn, new object[] { 1 }); byte[] value = (byte[])Value.GetValue(bits, null); byte[] seq = new byte[value.Length - 1]; System.Array.Copy(value, 1, seq, 0, value.Length - 1); asn = Ctor.Invoke(new object[] { seq }); object asn0 = Item.GetValue(asn, new object[] { 0 }); object asn1 = Item.GetValue(asn, new object[] { 1 }); modulus = (byte[])Value.GetValue(asn0, null); exponent = (byte[])Value.GetValue(asn1, null); // non-reflected version // Mono.Security.ASN1 asn = new Mono.Security.ASN1(publicKey64); // Mono.Security.ASN1 bits = asn[1]; // byte[] seq = new byte[bits.Length-1]; // System.Array.Copy(bits.Value, 1, seq, 0, bits.Length-1); // asn = new Mono.Security.ASN1(seq); // modulus = asn[0].Value; // exponent = asn[1].Value; }
// Attempt to locate the member as a property, and deal with it based on the given parameters // Returns: boolean indicating whether the command was handled here public static bool CallProperty(System.Type targetClass, string propertyName, string parameters) { // Attempt to find the property PropertyInfo targetProperty = targetClass.GetProperty(propertyName, BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy); object targetInstance = null; if (targetProperty == null) { targetInstance = GetMainOfClass(targetClass); if (targetInstance != null) { targetProperty = targetClass.GetProperty(propertyName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy); } } if (targetProperty == null || !IsAccessible(targetProperty)) { return(false); } // Fail: Couldn't find property, or it's marked inaccessible // If field is found, deal with it appropriately based on the parameters given if (parameters == null || parameters.Length < 1) { string output = GetPropertyValue(targetInstance, targetProperty); if (output == null) { return(false); } // Fail: Property is not of a supported type Echo(propertyName + " is " + output); return(true); // Success: Value is printed when no parameters given } if (IsCheat(targetProperty) && !cheats) { PrintCheatMessage(targetProperty.Name); } else { if (!SetPropertyValue(targetInstance, targetProperty, parameters.SplitUnlessInContainer(' ', '\"'))) { Echo("Invalid " + targetProperty.PropertyType.Name + ": " + parameters); } } return(true); // Success: Whether or not the field could be set (input was valid/invalid) the user is notified and the case is handled }
public static ServiceDescriptor?GetServiceDescriptor(Type serviceReflectionType) { var property = serviceReflectionType.GetProperty("Descriptor", BindingFlags.Public | BindingFlags.Static); if (property != null) { return((ServiceDescriptor?)property.GetValue(null)); } throw new InvalidOperationException($"Get not find Descriptor property on {serviceReflectionType.Name}."); }
void CopyText() { System.Type T = typeof(GUIUtility); System.Reflection.PropertyInfo systemCopyBufferProperty = T.GetProperty("systemCopyBuffer", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic); systemCopyBufferProperty.SetValue(null, text, null); // TextEditor te = new TextEditor(); // te.content = new GUIContent(text); // te.SelectAll(); // te.Copy(); }
internal static MessageDescriptor?GetMessageDescriptor(Type typeToConvert) { var property = typeToConvert.GetProperty("Descriptor", BindingFlags.Static | BindingFlags.Public, binder: null, typeof(MessageDescriptor), Type.EmptyTypes, modifiers: null); if (property == null) { return(null); } return(property.GetValue(null, null) as MessageDescriptor); }
public tk2dSpriteThumbnailCache() { System.Type guiClipType = System.Type.GetType("UnityEngine.GUIClip,UnityEngine"); if (guiClipType != null) { guiClipVisibleRectProperty = guiClipType.GetProperty("visibleRect"); } mat = new Material(Shader.Find("Hidden/tk2d/EditorUtility")); mat.hideFlags = HideFlags.DontSave; }
PropertyInfo propertyInfo; // PropertyInfo object // ---------------------------------------- // // CONSTRUCTOR public AniValue(System.Object o, string n) { obj = o; name = n; objType = obj.GetType(); fieldInfo = objType.GetField(n, AniValue.bFlags); propertyInfo = objType.GetProperty(n, AniValue.bFlags); if (fieldInfo == null && propertyInfo == null) { throw new System.MissingMethodException("Property or field '" + n + "' not found on " + obj); } }
private void LockInspector(bool isLocked) { System.Type type = Assembly.GetAssembly(typeof(Editor)).GetType("UnityEditor.InspectorWindow"); FieldInfo field = type.GetField("m_AllInspectors", BindingFlags.Static | BindingFlags.NonPublic); System.Collections.ArrayList windows = new System.Collections.ArrayList(field.GetValue(null) as System.Collections.ICollection); foreach (var window in windows) { PropertyInfo property = type.GetProperty("isLocked"); property.SetValue(window, isLocked, null); } }
void Awake() { _panel = GetComponent <UIPanel> (); _firstAttrs = _container_firstAttr.GetComponentsInChildren <UILabel> (); System.Array.Sort <UILabel> (_firstAttrs, (x, y) => { return(x.name.CompareTo(y.name)); }); _secondAttrs = _container_secondAttr.GetComponentsInChildren <UILabel> (); System.Array.Sort <UILabel> (_secondAttrs, (x, y) => { return(x.name.CompareTo(y.name)); }); _comparisonAttrs = _container_comparison.GetComponentsInChildren <UILabel> (); System.Array.Sort <UILabel> (_comparisonAttrs, (x, y) => { return(x.name.CompareTo(y.name)); }); _firstAbilities = _container_firstAbility.GetComponentsInChildren <AbilityDisplayer> (); _secondAbilities = _container_secondAbility.GetComponentsInChildren <AbilityDisplayer> (); System.Comparison <AbilityDisplayer> cmp = delegate(AbilityDisplayer a, AbilityDisplayer b) { int ax, ay, bx, by; ay = System.Convert.ToInt32(a.transform.localPosition.y * 100); by = System.Convert.ToInt32(b.transform.localPosition.y * 100); if (ay < by) { return(1); } if (ay > by) { return(-1); } ax = System.Convert.ToInt32(a.transform.localPosition.x * 100); bx = System.Convert.ToInt32(b.transform.localPosition.x * 100); if (ax > bx) { return(1); } if (ax < bx) { return(-1); } return(0); }; System.Array.Sort <AbilityDisplayer> (_firstAbilities, cmp); System.Array.Sort <AbilityDisplayer> (_secondAbilities, cmp); _attrs = new PropertyInfo[_firstAttrs.Length]; System.Type typeOfCard = typeof(ConcreteCard); for (int i = 0; i < _attrs.Length; i++) { _attrs [i] = typeOfCard.GetProperty(_firstAttrs [i].name); } }
public static void SetClipboard(string value) { System.Type T = typeof(GUIUtility); PropertyInfo systemCopyBufferProperty = T.GetProperty("systemCopyBuffer", BindingFlags.Static | BindingFlags.NonPublic); if (systemCopyBufferProperty == null) { throw new System.Exception("Can't access clipboard object."); } systemCopyBufferProperty.SetValue(null, value, null); }
//Tipo de la variable public System.Type GetType() { //Obtenemos la propiedad del componente System.Type t = componente.GetType(); PropertyInfo prop = t.GetProperty(nombre); if (prop == null) { return(null); } //Devolvemos el valor de la propiedad return(prop.PropertyType); }
public void ToggleValue() { System.Type type = _component.GetType(); var propertyEnabled = type.GetProperty("enabled"); if (propertyEnabled != null) { propertyEnabled.SetValue(_component, !(bool)propertyEnabled.GetValue(_component)); } else { Debug.Log("It seems '" + _component + "' does not have 'enabled' property."); } }
protected static PropertyInfo GetProperty(Object target, string name) { System.Type lookupType = target.GetType(); do { PropertyInfo field = lookupType.GetProperty(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field != null) { return(field); } lookupType = lookupType.BaseType; } while (lookupType != typeof(MonoBehaviour)); return(null); }
public string[] GetSortingLayerNames() { try { System.Type v_internalEditorUtilityType = typeof(UnityEditorInternal.InternalEditorUtility); PropertyInfo v_sortingLayersProperty = v_internalEditorUtilityType.GetProperty("sortingLayerNames", BindingFlags.Static | BindingFlags.NonPublic); return((string[])v_sortingLayersProperty.GetValue(null, new object[0])); } catch {} List <string> v_list = new List <string>(); v_list.Add("Default"); return(v_list.ToArray()); }
private static PropertyInfo GetSystemCopyBufferProperty() { if (m_systemCopyBufferProperty == null) { System.Type T = typeof(GUIUtility); m_systemCopyBufferProperty = T.GetProperty("systemCopyBuffer", BindingFlags.Static | BindingFlags.NonPublic); if (m_systemCopyBufferProperty == null) { Debug.LogError("Can't access internal member 'GUIUtility.systemCopyBuffer' it may have been removed / renamed"); } } return(m_systemCopyBufferProperty); }
// get state of other asset private static bool GetUpdateInProgress(string reflectType, string reflectProperty) { System.Type type = System.Type.GetType(reflectType); if (type == null) { return(false); } System.Reflection.PropertyInfo property = type.GetProperty(reflectProperty); if (property == null) { return(false); } return((bool)property.GetValue(type, null)); }