コード例 #1
0
		public MetadataImporter(IErrorReporter errorReporter, ICompilation compilation, IAttributeStore attributeStore, CompilerOptions options) {
			_errorReporter = errorReporter;
			_compilation = compilation;
			_attributeStore = attributeStore;
			_minimizeNames = options.MinimizeScript;
			_systemObject = compilation.MainAssembly.Compilation.FindType(KnownTypeCode.Object);
			_typeSemantics = new Dictionary<ITypeDefinition, TypeSemantics>();
			_delegateSemantics = new Dictionary<ITypeDefinition, DelegateScriptSemantics>();
			_instanceMemberNamesByType = new Dictionary<ITypeDefinition, HashSet<string>>();
			_staticMemberNamesByType = new Dictionary<ITypeDefinition, HashSet<string>>();
			_methodSemantics = new Dictionary<IMethod, MethodScriptSemantics>();
			_propertySemantics = new Dictionary<IProperty, PropertyScriptSemantics>();
			_fieldSemantics = new Dictionary<IField, FieldScriptSemantics>();
			_eventSemantics = new Dictionary<IEvent, EventScriptSemantics>();
			_constructorSemantics = new Dictionary<IMethod, ConstructorScriptSemantics>();
			_propertyBackingFieldNames = new Dictionary<IProperty, Tuple<string, bool>>();
			_eventBackingFieldNames = new Dictionary<IEvent, Tuple<string, bool>>();
			_backingFieldCountPerType = new Dictionary<ITypeDefinition, int>();
			_internalTypeCountPerAssemblyAndNamespace = new Dictionary<Tuple<IAssembly, string>, int>();
			_ignoredMembers = new HashSet<IMember>();

			var sna = _attributeStore.AttributesFor(compilation.MainAssembly).GetAttribute<ScriptNamespaceAttribute>();
			if (sna != null) {
				if (sna.Name == null || (sna.Name != "" && !sna.Name.IsValidNestedJavaScriptIdentifier())) {
					Message(Messages._7002, default(DomRegion), "assembly");
				}
			}
		}
コード例 #2
0
        public static bool?ShouldGenericArgumentsBeIncluded(IMethod method, IAttributeStore attributeStore)
        {
            var iga = attributeStore.AttributesFor(method).GetAttribute <IncludeGenericArgumentsAttribute>();

            if (iga != null)
            {
                return(iga.Include);
            }
            var imp = attributeStore.AttributesFor(method.DeclaringTypeDefinition).GetAttribute <ImportedAttribute>();

            if (imp != null)
            {
                return(false);
            }
            var def = attributeStore.AttributesFor(method.ParentAssembly).GetAttribute <IncludeGenericArgumentsDefaultAttribute>();

            switch (def != null ? def.MethodDefault : GenericArgumentsDefault.IncludeExceptImported)
            {
            case GenericArgumentsDefault.IncludeExceptImported:
                return(true);

            case GenericArgumentsDefault.Ignore:
                return(false);

            case GenericArgumentsDefault.RequireExplicitSpecification:
                return(null);

            default:
                throw new ArgumentException("Invalid generic arguments default " + def.TypeDefault);
            }
        }
		public override void ApplyTo(IAssembly assembly, IAttributeStore attributeStore, IErrorReporter errorReporter) {
			foreach (var t in assembly.GetAllTypeDefinitions()) {
				if (!attributeStore.AttributesFor(t).HasAttribute<DefaultMemberReflectabilityAttribute>()) {
					ApplyTo(t, attributeStore, errorReporter);
				}
			}
		}
コード例 #4
0
 void FillStoreDefault(IAttributeStore <string> store)
 {
     foreach (var line in attributes)
     {
         store.PlaceAndGetLinks(line);
     }
 }
コード例 #5
0
 public Linker(IMetadataImporter metadataImporter, INamer namer, IAttributeStore attributeStore, ICompilation compilation)
 {
     _metadataImporter = metadataImporter;
     _namer            = namer;
     _attributeStore   = attributeStore;
     _compilation      = compilation;
 }
コード例 #6
0
 private IntroducedNamesGatherer(IMetadataImporter metadataImporter, IAssembly mainAssembly, IAttributeStore attributeStore)
 {
     _metadataImporter = metadataImporter;
     _mainAssembly     = mainAssembly;
     _attributeStore   = attributeStore;
     _mainModuleName   = MetadataUtils.GetModuleName(_mainAssembly, attributeStore);
 }
コード例 #7
0
 /// <summary>
 /// Sets multiple attributes on this object.
 /// </summary>
 /// <param name="values">Attribute store.</param>
 public virtual void SetAttributes(IAttributeStore values)
 {
     foreach (string name in values.GetAttributeNames())
     {
         object value = values.GetAttribute(name);
         SetAttribute(name, value);
     }
 }
コード例 #8
0
		public RuntimeLibrary(IMetadataImporter metadataImporter, IErrorReporter errorReporter, ICompilation compilation, INamer namer, IAttributeStore attributeStore) {
			_metadataImporter = metadataImporter;
			_errorReporter = errorReporter;
			_compilation = compilation;
			_namer = namer;
			_attributeStore = attributeStore;
			_omitDowncasts = MetadataUtils.OmitDowncasts(compilation, _attributeStore);
			_omitNullableChecks = MetadataUtils.OmitNullableChecks(compilation, _attributeStore);
		}
コード例 #9
0
		private void RunAutomaticMetadataAttributeAppliers(IAttributeStore store, ICompilation compilation) {
			var processors = new IAutomaticMetadataAttributeApplier[] { new MakeMembersWithScriptableAttributesReflectable(store) };
			foreach (var p in processors) {
				foreach (var asm in compilation.Assemblies)
					p.Process(asm);
				foreach (var t in compilation.GetAllTypeDefinitions())
					p.Process(t);
			}
		}
コード例 #10
0
 public override void ApplyTo(IAssembly assembly, IAttributeStore attributeStore, IErrorReporter errorReporter)
 {
     foreach (var t in assembly.GetAllTypeDefinitions())
     {
         if (!attributeStore.AttributesFor(t).HasAttribute <DefaultMemberReflectabilityAttribute>())
         {
             ApplyTo(t, attributeStore, errorReporter);
         }
     }
 }
コード例 #11
0
 public RuntimeLibrary(IMetadataImporter metadataImporter, IErrorReporter errorReporter, ICompilation compilation, INamer namer, IAttributeStore attributeStore)
 {
     _metadataImporter   = metadataImporter;
     _errorReporter      = errorReporter;
     _compilation        = compilation;
     _namer              = namer;
     _attributeStore     = attributeStore;
     _omitDowncasts      = MetadataUtils.OmitDowncasts(compilation, _attributeStore);
     _omitNullableChecks = MetadataUtils.OmitNullableChecks(compilation, _attributeStore);
 }
コード例 #12
0
        private static string GetTypeModuleName(ITypeDefinition type, IAttributeStore attributeStore)
        {
            string result;

            if (!_typeModuleNames.TryGetValue(type, out result))
            {
                _typeModuleNames[type] = result = MetadataUtils.GetModuleName(type, attributeStore);
            }
            return(result);
        }
コード例 #13
0
		public static void MakeKnockoutProperty(IProperty property, IAttributeStore attributeStore) {
			var getter = attributeStore.AttributesFor(property.Getter);
			getter.ReplaceAttribute(new ScriptNameAttribute("{owner}"));
			getter.ReplaceAttribute(new DontGenerateAttribute());
			var setter = attributeStore.AttributesFor(property.Setter);
			setter.ReplaceAttribute(new ScriptNameAttribute("{owner}"));
			setter.ReplaceAttribute(new DontGenerateAttribute());
			var prop = attributeStore.AttributesFor(property);
			prop.ReplaceAttribute(new CustomInitializationAttribute("{$KnockoutApi.Knockout}.observable({value})"));
			prop.ReplaceAttribute(new BackingFieldNameAttribute("{owner}"));
		}
コード例 #14
0
ファイル: Previewer.cs プロジェクト: EugeneAnykey/Clope4
        // init
        public Previewer(IEnumerable <ITransaction> transactions, IEnumerable <ICluster> clusters, IAttributeStore <T> store)
        {
            this.transactions = transactions;
            this.clusters     = clusters;
            this.store        = store;

            resultForClusters = new List <int[]>();

            attributes = new T[0];
            links      = new int[0];
        }
コード例 #15
0
 private ImportVisitor(IMetadataImporter metadataImporter, INamer namer, IAttributeStore attributeStore, IAssembly mainAssembly, HashSet <string> usedSymbols, JsExpression currentAssembly)
 {
     _metadataImporter = metadataImporter;
     _namer            = namer;
     _attributeStore   = attributeStore;
     _mainModuleName   = MetadataUtils.GetModuleName(mainAssembly, attributeStore);
     _mainAssembly     = mainAssembly;
     _usedSymbols      = usedSymbols;
     _currentAssembly  = currentAssembly;
     _moduleAliases    = new Dictionary <string, string>();
 }
コード例 #16
0
ファイル: AttributeStore.cs プロジェクト: sandboxorg/AMFCore
 /// <summary>
 /// Sets multiple attributes on this object.
 /// </summary>
 /// <param name="values">Attribute store.</param>
 public virtual void SetAttributes(IAttributeStore values)
 {
     lock (((ICollection)_attributes).SyncRoot)
     {
         foreach (string name in values.GetAttributeNames())
         {
             object value = values.GetAttribute(name);
             SetAttribute(name, value);
         }
     }
 }
コード例 #17
0
 public virtual void SetAttributes(IAttributeStore values)
 {
     lock (((ICollection)this._attributes).SyncRoot)
     {
         foreach (string str in values.GetAttributeNames())
         {
             object attribute = values.GetAttribute(str);
             this.SetAttribute(str, attribute);
         }
     }
 }
コード例 #18
0
 public static string GetModuleName(ITypeDefinition type, IAttributeStore attributeStore)
 {
     for (var current = type; current != null; current = current.DeclaringTypeDefinition)
     {
         var mna = attributeStore.AttributesFor(type).GetAttribute <ModuleNameAttribute>();
         if (mna != null)
         {
             return(!String.IsNullOrEmpty(mna.ModuleName) ? mna.ModuleName : null);
         }
     }
     return(GetModuleName(type.ParentAssembly, attributeStore));
 }
コード例 #19
0
 public override void SetAttributes(IAttributeStore values)
 {
     BeginUpdate();
     try {
         _so.SetAttributes(values);
     } finally {
         EndUpdate();
     }
     foreach (ISharedObjectListener listener in _serverListeners)
     {
         listener.OnSharedObjectUpdate(this, values);
     }
 }
		public override void ApplyTo(IEntity entity, IAttributeStore attributeStore, IErrorReporter errorReporter) {
			var type = entity as ITypeDefinition;
			if (type == null)
				return;

			foreach (var m in type.Members) {
				var attributes = attributeStore.AttributesFor(m);
				if (!attributes.HasAttribute<ReflectableAttribute>()) {
					if (IsMemberReflectable(m)) {
						attributes.Add(new ReflectableAttribute(true));
					}
				}
			}
		}
コード例 #21
0
ファイル: Tester.cs プロジェクト: EugeneAnykey/Clope4
        // logic
        void PrepareTest()
        {
            attributeStore = _GetAttributeStore();

            logger.Write($"Prepare test>");
            logger.Write($"> file      > {vars.Filename}");
            logger.Write($"> repulsion > {vars.Repulsion}");
            logger.Write($"> delimeter > {vars.Separator}");
            logger.Write($"> line to skip > {vars.FirstLinesToSkip}");
            logger.Write($"> column to view > {vars.ColumnToView}");

            clope.Repulsion = vars.Repulsion;
            clope.StepDone += (step, changes) => StepInfo(step, changes);
            logger.Write("------");
        }
コード例 #22
0
		public override void ApplyTo(IEntity entity, IAttributeStore attributeStore, IErrorReporter errorReporter) {
			if (IsKnockoutProperty) {
				var p = (IProperty)entity;

				if (p.IsStatic) {
					errorReporter.Message(MessageSeverity.Error, 8000, "The property {0} cannot have a [KnockoutPropertyAttribute] because it is static", p.FullName);
				}
				else if (MetadataUtils.IsAutoProperty(p) == false) {
					errorReporter.Message(MessageSeverity.Error, 8001, "The property {0} cannot be a knockout property because it is not an auto-property", p.FullName);
				}
				else {
					MakeKnockoutProperty((IProperty)entity, attributeStore);
				}
			}
		}
コード例 #23
0
		public override void ApplyTo(IEntity entity, IAttributeStore attributeStore, IErrorReporter errorReporter) {
			foreach (var p in ((ITypeDefinition)entity).GetProperties(options: GetMemberOptions.IgnoreInheritedMembers)) {
				if (attributeStore.AttributesFor(p).HasAttribute<KnockoutPropertyAttribute>())
					continue;
				if (p.IsStatic)
					continue;

				if (MetadataUtils.IsAutoProperty(p) == false) {
					errorReporter.Message(MessageSeverity.Error, 8001, "The property {0} is not an auto-property so because its containing type has a [KnockoutModelAttribute], the property must be decorated with [KnockoutPropertyAttribute(false)]", p.FullName);
					continue;
				}

				KnockoutPropertyAttribute.MakeKnockoutProperty(p, attributeStore);
			}
		}
コード例 #24
0
        public OOPEmulator(ICompilation compilation, IMetadataImporter metadataImporter, IRuntimeLibrary runtimeLibrary, INamer namer, ILinker linker, IAttributeStore attributeStore, IErrorReporter errorReporter)
        {
            _compilation  = compilation;
            _systemScript = new JsTypeReferenceExpression(compilation.FindType(new FullTypeName("System.Script")).GetDefinition());
            _systemObject = new JsTypeReferenceExpression(compilation.FindType(KnownTypeCode.Object).GetDefinition());

            _metadataImporter = metadataImporter;
            _runtimeLibrary   = runtimeLibrary;
            _namer            = namer;
            _linker           = linker;
            _attributeStore   = attributeStore;
            _errorReporter    = errorReporter;
            _defaultReflectionRuntimeContext = new ReflectionRuntimeContext(false, _systemObject, _namer);
            _genericSpecializationReflectionRuntimeContext = new ReflectionRuntimeContext(true, _systemObject, _namer);
        }
コード例 #25
0
        public static void MakeKnockoutProperty(IProperty property, IAttributeStore attributeStore)
        {
            var getter = attributeStore.AttributesFor(property.Getter);

            getter.ReplaceAttribute(new ScriptNameAttribute("{owner}"));
            getter.ReplaceAttribute(new DontGenerateAttribute());
            var setter = attributeStore.AttributesFor(property.Setter);

            setter.ReplaceAttribute(new ScriptNameAttribute("{owner}"));
            setter.ReplaceAttribute(new DontGenerateAttribute());
            var prop = attributeStore.AttributesFor(property);

            prop.ReplaceAttribute(new CustomInitializationAttribute("{$KnockoutApi.Knockout}.observable({value})"));
            prop.ReplaceAttribute(new BackingFieldNameAttribute("{owner}"));
        }
コード例 #26
0
        private void RunAutomaticMetadataAttributeAppliers(IAttributeStore store, ICompilation compilation)
        {
            var processors = new IAutomaticMetadataAttributeApplier[] { new MakeMembersWithScriptableAttributesReflectable(store) };

            foreach (var p in processors)
            {
                foreach (var asm in compilation.Assemblies)
                {
                    p.Process(asm);
                }
                foreach (var t in compilation.GetAllTypeDefinitions())
                {
                    p.Process(t);
                }
            }
        }
コード例 #27
0
        public override void SetAttributes(IAttributeStore values)
        {
            if (values == null)
            {
                return;
            }

            BeginUpdate();
            try {
                foreach (string name in values.GetAttributeNames())
                {
                    SetAttribute(name, values.GetAttribute(name));
                }
            } finally {
                EndUpdate();
            }
        }
コード例 #28
0
ファイル: SharedObject.cs プロジェクト: Joy011024/PickUpData
 public override void SetAttributes(IAttributeStore values)
 {
     if (values != null)
     {
         this.BeginUpdate();
         try
         {
             foreach (string str in values.GetAttributeNames())
             {
                 this.SetAttribute(str, values.GetAttribute(str));
             }
         }
         finally
         {
             this.EndUpdate();
         }
     }
 }
コード例 #29
0
        public override void ApplyTo(IEntity entity, IAttributeStore attributeStore, IErrorReporter errorReporter)
        {
            if (IsKnockoutProperty)
            {
                var p = (IProperty)entity;

                if (p.IsStatic)
                {
                    errorReporter.Message(MessageSeverity.Error, 8000, "The property {0} cannot have a [KnockoutPropertyAttribute] because it is static", p.FullName);
                }
                else if (MetadataUtils.IsAutoProperty(p) == false)
                {
                    errorReporter.Message(MessageSeverity.Error, 8001, "The property {0} cannot be a knockout property because it is not an auto-property", p.FullName);
                }
                else
                {
                    MakeKnockoutProperty((IProperty)entity, attributeStore);
                }
            }
        }
コード例 #30
0
        public override void ApplyTo(IEntity entity, IAttributeStore attributeStore, IErrorReporter errorReporter)
        {
            var type = entity as ITypeDefinition;

            if (type == null)
            {
                return;
            }

            foreach (var m in type.Members)
            {
                var attributes = attributeStore.AttributesFor(m);
                if (!attributes.HasAttribute <ReflectableAttribute>())
                {
                    if (IsMemberReflectable(m))
                    {
                        attributes.Add(new ReflectableAttribute(true));
                    }
                }
            }
        }
コード例 #31
0
        public override void ApplyTo(IEntity entity, IAttributeStore attributeStore, IErrorReporter errorReporter)
        {
            foreach (var p in ((ITypeDefinition)entity).GetProperties(options: GetMemberOptions.IgnoreInheritedMembers))
            {
                if (attributeStore.AttributesFor(p).HasAttribute <KnockoutPropertyAttribute>())
                {
                    continue;
                }
                if (p.IsStatic)
                {
                    continue;
                }

                if (MetadataUtils.IsAutoProperty(p) == false)
                {
                    errorReporter.Message(MessageSeverity.Error, 8001, "The property {0} is not an auto-property so because its containing type has a [KnockoutModelAttribute], the property must be decorated with [KnockoutPropertyAttribute(false)]", p.FullName);
                    continue;
                }

                KnockoutPropertyAttribute.MakeKnockoutProperty(p, attributeStore);
            }
        }
コード例 #32
0
		/// <summary>
		/// Determines the preferred name for a member. The first item is the name, the second item is true if the name was explicitly specified.
		/// </summary>
		public static Tuple<string, bool> DeterminePreferredMemberName(IMember member, bool minimizeNames, IAttributeStore attributeStore) {
			member = UnwrapValueTypeConstructor(member);

			bool isConstructor = member is IMethod && ((IMethod)member).IsConstructor;
			bool isAccessor = member is IMethod && ((IMethod)member).IsAccessor;
			bool isPreserveMemberCase = IsPreserveMemberCase(member.DeclaringTypeDefinition, attributeStore);

			string defaultName;
			if (isConstructor) {
				defaultName = "$ctor";
			}
			else if (!CanBeMinimized(member, attributeStore)) {
				defaultName = isPreserveMemberCase ? member.Name : MakeCamelCase(member.Name);
			}
			else {
				if (minimizeNames && member.DeclaringType.Kind != TypeKind.Interface)
					defaultName = null;
				else
					defaultName = "$" + (isPreserveMemberCase ? member.Name : MakeCamelCase(member.Name));
			}

			var attributes = attributeStore.AttributesFor(member);

			var asa = attributes.GetAttribute<AlternateSignatureAttribute>();
			if (asa != null) {
				var otherMembers = member.DeclaringTypeDefinition.Methods.Where(m => m.Name == member.Name && !attributeStore.AttributesFor(m).HasAttribute<AlternateSignatureAttribute>() && !attributeStore.AttributesFor(m).HasAttribute<NonScriptableAttribute>() && !attributeStore.AttributesFor(m).HasAttribute<InlineCodeAttribute>()).ToList();
				if (otherMembers.Count == 1) {
					return DeterminePreferredMemberName(otherMembers[0], minimizeNames, attributeStore);
				}
				else {
					return Tuple.Create(member.Name, false);	// Error
				}
			}

			var sna = attributes.GetAttribute<ScriptNameAttribute>();
			if (sna != null) {
				string name = sna.Name;
				if (IsNamedValues(member.DeclaringTypeDefinition, attributeStore) && (name == "" || !name.IsValidJavaScriptIdentifier())) {
					return Tuple.Create(defaultName, false);	// For named values enum, allow the use to specify an empty or invalid value, which will only be used as the literal value for the field, not for the name.
				}
				if (name == "" && isConstructor)
					name = "$ctor";
				return Tuple.Create(name, true);
			}
			
			if (isConstructor && IsImported(member.DeclaringTypeDefinition, attributeStore)) {
				return Tuple.Create("$ctor", true);
			}

			var ica = attributes.GetAttribute<InlineCodeAttribute>();
			if (ica != null) {
				if (ica.GeneratedMethodName != null)
					return Tuple.Create(ica.GeneratedMethodName, true);
			}

			if (attributes.HasAttribute<PreserveCaseAttribute>())
				return Tuple.Create(member.Name, true);

			bool preserveName = (!isConstructor && !isAccessor && (   attributes.HasAttribute<PreserveNameAttribute>()
			                                                       || attributes.HasAttribute<InstanceMethodOnFirstArgumentAttribute>()
			                                                       || IsPreserveMemberNames(member.DeclaringTypeDefinition, attributeStore) && member.ImplementedInterfaceMembers.Count == 0 && !member.IsOverride)
			                                                       || (IsSerializable(member.DeclaringTypeDefinition, attributeStore) && !member.IsStatic && (member is IProperty || member is IField)))
			                                                       || (IsNamedValues(member.DeclaringTypeDefinition, attributeStore) && member is IField);

			if (preserveName)
				return Tuple.Create(isPreserveMemberCase ? member.Name : MakeCamelCase(member.Name), true);

			return Tuple.Create(defaultName, false);
		}
コード例 #33
0
		public static bool CanBeMinimized(IMember member, IAttributeStore attributeStore) {
			return !member.IsExternallyVisible() || attributeStore.AttributesFor(member.ParentAssembly).HasAttribute<MinimizePublicNamesAttribute>();
		}
コード例 #34
0
        public static bool DoesTypeObeyTypeSystem(ITypeDefinition type, IAttributeStore attributeStore)
        {
            var ia = attributeStore.AttributesFor(type).GetAttribute <ImportedAttribute>();

            return(ia == null || ia.ObeysTypeSystem);
        }
コード例 #35
0
 /// <summary>
 /// Sets multiple attributes on this object.
 /// </summary>
 /// <param name="values">Attribute store.</param>
 public override void SetAttributes(IAttributeStore values)
 {
     base.SetAttributes(values);
     OnModified();
 }
コード例 #36
0
		public static string GetModuleName(IAssembly assembly, IAttributeStore attributeStore) {
			var mna = attributeStore.AttributesFor(assembly).GetAttribute<ModuleNameAttribute>();
			return (mna != null && !String.IsNullOrEmpty(mna.ModuleName) ? mna.ModuleName : null);
		}
		public MakeMembersWithScriptableAttributesReflectable(IAttributeStore attributeStore) {
			_attributeStore   = attributeStore;
		}
コード例 #38
0
		public static string GetSerializableTypeCheckCode(ITypeDefinition type, IAttributeStore attributeStore) {
			var attr = attributeStore.AttributesFor(type).GetAttribute<ScriptSerializableAttribute>();
			return attr != null ? attr.TypeCheckCode : null;
		}
コード例 #39
0
        public static string GetModuleName(IAssembly assembly, IAttributeStore attributeStore)
        {
            var mna = attributeStore.AttributesFor(assembly).GetAttribute <ModuleNameAttribute>();

            return(mna != null && !String.IsNullOrEmpty(mna.ModuleName) ? mna.ModuleName : null);
        }
コード例 #40
0
		public static IEnumerable<KeyValuePair<string,string>> GetAdditionalDependencies(IAssembly assembly, IAttributeStore attributeStore)
		{
			return attributeStore.AttributesFor(assembly).GetAttributes<AdditionalDependencyAttribute>()
				.Select(a => new KeyValuePair<string,string>(a.ModuleName, a.InstanceName));
		}
コード例 #41
0
		public static bool DoesTypeObeyTypeSystem(ITypeDefinition type, IAttributeStore attributeStore) {
			var ia = attributeStore.AttributesFor(type).GetAttribute<ImportedAttribute>();
			return ia == null || ia.ObeysTypeSystem;
		}
コード例 #42
0
		public static bool IsMixin(ITypeDefinition type, IAttributeStore attributeStore) {
			return attributeStore.AttributesFor(type).HasAttribute<MixinAttribute>();
		}
コード例 #43
0
		public static bool IsImported(ITypeDefinition type, IAttributeStore attributeStore) {
			return attributeStore.AttributesFor(type).HasAttribute<ImportedAttribute>();
		}
コード例 #44
0
 public TestRewriter(IErrorReporter errorReporter, IRuntimeLibrary runtimeLibrary, IAttributeStore attributeStore)
 {
     _errorReporter  = errorReporter;
     _runtimeLibrary = runtimeLibrary;
     _attributeStore = attributeStore;
 }
コード例 #45
0
        public override void SetAttributes(IAttributeStore values) 
		{
			if (values == null) 
				return;

			BeginUpdate();
            try
            {
                foreach (string name in values.GetAttributeNames())
                {
                    SetAttribute(name, values.GetAttribute(name));
                }
            }
            finally
            {
                EndUpdate();
            }
		}
コード例 #46
0
		public static bool IsSerializable(ITypeDefinition type, IAttributeStore attributeStore) {
			return attributeStore.AttributesFor(type).HasAttribute<ScriptSerializableAttribute>() || (type.GetAllBaseTypeDefinitions().Any(td => td.FullName == "System.Record") && type.FullName != "System.Record");
		}
コード例 #47
0
		public static bool? ShouldGenericArgumentsBeIncluded(IMethod method, IAttributeStore attributeStore) {
			var iga = attributeStore.AttributesFor(method).GetAttribute<IncludeGenericArgumentsAttribute>();
			if (iga != null)
				return iga.Include;
			var imp = attributeStore.AttributesFor(method.DeclaringTypeDefinition).GetAttribute<ImportedAttribute>();
			if (imp != null)
				return false;
			var def = attributeStore.AttributesFor(method.ParentAssembly).GetAttribute<IncludeGenericArgumentsDefaultAttribute>();
			switch (def != null ? def.MethodDefault : GenericArgumentsDefault.IncludeExceptImported) {
				case GenericArgumentsDefault.IncludeExceptImported:
					return true;
				case GenericArgumentsDefault.Ignore:
					return false;
				case GenericArgumentsDefault.RequireExplicitSpecification:
					return null;
				default:
					throw new ArgumentException("Invalid generic arguments default " + def.TypeDefault);
			}
		}
コード例 #48
0
        /// <summary>
        /// Determines the preferred name for a member. The first item is the name, the second item is true if the name was explicitly specified.
        /// </summary>
        public static Tuple <string, bool> DeterminePreferredMemberName(IMember member, bool minimizeNames, IAttributeStore attributeStore)
        {
            member = UnwrapValueTypeConstructor(member);

            bool isConstructor        = member is IMethod && ((IMethod)member).IsConstructor;
            bool isAccessor           = member is IMethod && ((IMethod)member).IsAccessor;
            bool isPreserveMemberCase = IsPreserveMemberCase(member.DeclaringTypeDefinition, attributeStore);

            string defaultName;

            if (isConstructor)
            {
                defaultName = "$ctor";
            }
            else if (!CanBeMinimized(member, attributeStore))
            {
                defaultName = isPreserveMemberCase ? member.Name : MakeCamelCase(member.Name);
            }
            else
            {
                if (minimizeNames && member.DeclaringType.Kind != TypeKind.Interface)
                {
                    defaultName = null;
                }
                else
                {
                    defaultName = "$" + (isPreserveMemberCase ? member.Name : MakeCamelCase(member.Name));
                }
            }

            var attributes = attributeStore.AttributesFor(member);

            var asa = attributes.GetAttribute <AlternateSignatureAttribute>();

            if (asa != null)
            {
                var otherMembers = member.DeclaringTypeDefinition.Methods.Where(m => m.Name == member.Name && !attributeStore.AttributesFor(m).HasAttribute <AlternateSignatureAttribute>() && !attributeStore.AttributesFor(m).HasAttribute <NonScriptableAttribute>() && !attributeStore.AttributesFor(m).HasAttribute <InlineCodeAttribute>()).ToList();
                if (otherMembers.Count == 1)
                {
                    return(DeterminePreferredMemberName(otherMembers[0], minimizeNames, attributeStore));
                }
                else
                {
                    return(Tuple.Create(member.Name, false));                           // Error
                }
            }

            var sna = attributes.GetAttribute <ScriptNameAttribute>();

            if (sna != null)
            {
                string name = sna.Name;
                if (IsNamedValues(member.DeclaringTypeDefinition, attributeStore) && (name == "" || !name.IsValidJavaScriptIdentifier()))
                {
                    return(Tuple.Create(defaultName, false));                           // For named values enum, allow the use to specify an empty or invalid value, which will only be used as the literal value for the field, not for the name.
                }
                if (name == "" && isConstructor)
                {
                    name = "$ctor";
                }
                return(Tuple.Create(name, true));
            }

            if (isConstructor && IsImported(member.DeclaringTypeDefinition, attributeStore))
            {
                return(Tuple.Create("$ctor", true));
            }

            var ica = attributes.GetAttribute <InlineCodeAttribute>();

            if (ica != null)
            {
                if (ica.GeneratedMethodName != null)
                {
                    return(Tuple.Create(ica.GeneratedMethodName, true));
                }
            }

            if (attributes.HasAttribute <PreserveCaseAttribute>())
            {
                return(Tuple.Create(member.Name, true));
            }

            bool preserveName = (!isConstructor && !isAccessor && (attributes.HasAttribute <PreserveNameAttribute>() ||
                                                                   attributes.HasAttribute <InstanceMethodOnFirstArgumentAttribute>() ||
                                                                   IsPreserveMemberNames(member.DeclaringTypeDefinition, attributeStore) && member.ImplementedInterfaceMembers.Count == 0 && !member.IsOverride) ||
                                 (IsSerializable(member.DeclaringTypeDefinition, attributeStore) && !member.IsStatic && (member is IProperty || member is IField))) ||
                                (IsNamedValues(member.DeclaringTypeDefinition, attributeStore) && member is IField);

            if (preserveName)
            {
                return(Tuple.Create(isPreserveMemberCase ? member.Name : MakeCamelCase(member.Name), true));
            }

            return(Tuple.Create(defaultName, false));
        }
コード例 #49
0
		public static string GetModuleName(ITypeDefinition type, IAttributeStore attributeStore) {
			for (var current = type; current != null; current = current.DeclaringTypeDefinition) {
				var mna = attributeStore.AttributesFor(type).GetAttribute<ModuleNameAttribute>();
				if (mna != null)
					return !String.IsNullOrEmpty(mna.ModuleName) ? mna.ModuleName : null;
			}
			return GetModuleName(type.ParentAssembly, attributeStore);
		}
コード例 #50
0
 public static bool IsSerializable(ITypeDefinition type, IAttributeStore attributeStore)
 {
     return(attributeStore.AttributesFor(type).HasAttribute <ScriptSerializableAttribute>() || (type.GetAllBaseTypeDefinitions().Any(td => td.FullName == "System.Record") && type.FullName != "System.Record"));
 }
コード例 #51
0
 public static bool CanBeMinimized(IMember member, IAttributeStore attributeStore)
 {
     return(!member.IsExternallyVisible() || attributeStore.AttributesFor(member.ParentAssembly).HasAttribute <MinimizePublicNamesAttribute>());
 }
コード例 #52
0
		public static bool IsPreserveMemberCase(ITypeDefinition type, IAttributeStore attributeStore) {
			var pmca = attributeStore.AttributesFor(type).GetAttribute<PreserveMemberCaseAttribute>() ?? attributeStore.AttributesFor(type.ParentAssembly).GetAttribute<PreserveMemberCaseAttribute>();
			return pmca != null && pmca.Preserve;
		}
コード例 #53
0
        public static bool IsReflectable(IMember member, IAttributeStore attributeStore)
        {
            var ra = attributeStore.AttributesFor(member).GetAttribute <ReflectableAttribute>();

            return(ra != null && ra.Reflectable);
        }
コード例 #54
0
        /// <summary>
        /// Sets multiple attributes on this object.
        /// </summary>
        /// <param name="values">Attribute store.</param>
        public void SetAttributes(IAttributeStore values)
		{
			_scope.SetAttributes(values);
		}
コード例 #55
0
        public static string GetSerializableTypeCheckCode(ITypeDefinition type, IAttributeStore attributeStore)
        {
            var attr = attributeStore.AttributesFor(type).GetAttribute <ScriptSerializableAttribute>();

            return(attr != null ? attr.TypeCheckCode : null);
        }
コード例 #56
0
		public static bool IsReflectable(IMember member, IAttributeStore attributeStore) {
			var ra = attributeStore.AttributesFor(member).GetAttribute<ReflectableAttribute>();
			return ra != null && ra.Reflectable;
		}
コード例 #57
0
		public static bool IsNamedValues(ITypeDefinition type, IAttributeStore attributeStore) {
			return attributeStore.AttributesFor(type).HasAttribute<NamedValuesAttribute>();
		}
コード例 #58
0
		public static bool IsResources(ITypeDefinition type, IAttributeStore attributeStore) {
			return attributeStore.AttributesFor(type).HasAttribute<ResourcesAttribute>();
		}
コード例 #59
0
ファイル: SharedObjectScope.cs プロジェクト: GodLesZ/svn-dump
		public override void SetAttributes(IAttributeStore values) {
			BeginUpdate();
			try {
				_so.SetAttributes(values);
			} finally {
				EndUpdate();
			}
			foreach (ISharedObjectListener listener in _serverListeners) {
				listener.OnSharedObjectUpdate(this, values);
			}
		}
コード例 #60
0
		public static bool IsGlobalMethods(ITypeDefinition type, IAttributeStore attributeStore) {
			return attributeStore.AttributesFor(type).HasAttribute<GlobalMethodsAttribute>();
		}